<?php
class Pageley_Commerce_Command_AddItemToOrder extends Pageley_Controller_Command_TransactionalRead {

	private $articleId;
	private $quantity;

	public function setArticleId($articleId) {
		$this->articleId = $articleId;
	}

	public function setQuantity($quantity) {
		$this->quantity = $quantity;
	}

	protected function executeInternal() {
		$order = $this->getSession()->get(Pageley_Commerce_Session::ORDER);
		if($order === null) {
			$order = new Pageley_Commerce_Domain_Order();
			$this->getSession()->set(Pageley_Commerce_Session::ORDER, $order);
		}
		$unitOfWork = $this->getUnitOfWork();
		$article = $unitOfWork->find(Pageley_Commerce_Domain_Article::type(), $this->articleId);
		$orderItem = new Pageley_Commerce_Domain_OrderItem($article, $this->quantity);
		$order->add($orderItem);
	}
}